﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lucene.Net.Index;
using Lucene.Net.Store;
using Lucene.Net.Analysis.Standard;
using System.IO;

namespace luceneindex
{
    /// <summary>
    /// Lucene Hot Copy
    /// <remarks>
    ///     according the url : http://www.cnblogs.com/jinzhao/archive/2013/01/14/2859715.html
    /// </remarks>
    /// </summary>
    public class LuceneHotCopy
    {
        public void BakFile(string path)
        {
            IndexDeletionPolicy policy = new KeepOnlyLastCommitDeletionPolicy();

            SnapshotDeletionPolicy snapshotter = new SnapshotDeletionPolicy(policy);

            IndexWriter writer = new IndexWriter(
                new SimpleFSDirectory(new DirectoryInfo(path)),
                new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29),
                snapshotter, IndexWriter.MaxFieldLength.UNLIMITED);

            try
            {
                IndexCommit commit = snapshotter.Snapshot() as IndexCommit;
                ICollection<string> files = commit.FileNames;
                /*<iterate over & copy files from fileNames>*/
            }
            finally
            {
                snapshotter.Release();
            }
        }
    }
}
